﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 实验报告2._1
{
    class Program
    {
        static void Main(string[] args)
        {
            CzPoint p1 = new CzPoint(1, 2);
            CzPoint p2 = new CzPoint(2, 3);
            Console.WriteLine("点一({0},{1})与点二({2},{3})相等吗？ 答：{4}", p1.X,p1.Y,p2.X,p2.Y,p1==p2);
            p1.Move(1, 1);
            Console.WriteLine("移动后的点一({0},{1})与点二({2},{3})相等吗？ 答：{4}", p1.X, p1.Y, p2.X, p2.Y, p1 == p2);
            Console.WriteLine("移动后的点一({0},{1})与点二({2},{3})不相等吗？ 答：{4}", p1.X, p1.Y, p2.X, p2.Y, p1 != p2);
            CzPoint p3 = new CzPoint(2, 2);
            CzPoint p4 = new CzPoint(5, 10);
            CzPoint.CzLine line1 = new CzPoint.CzLine(p3, p4);
            Console.WriteLine("输入的点是否在直线上? 答：{0}。",line1.Contains(new CzPoint(4,4)));
            CzPoint.CzLine line2 = new CzPoint.CzLine(1, 0);
            Console.WriteLine("line1与line2是否相等？ 答：{0}。",line1==line2);
            Console.WriteLine("输入的点是否在直线上 ? 答：{0}。",line2.Contains(new CzPoint(4,4)));
            Console.ReadKey();
        }
    }
    public class CzPoint
    {
       

        public double X {
            get;
            set;
        }
        public double Y
        {
            get;
            set;
        }
        public CzPoint(double x,double y)
        {
            this.X = x;
            this.Y = y;
        }
        public void Move(double dx,double dy)
        {
            this.X += dx;
            this.Y += dy;
        }
        public static bool operator ==(CzPoint p1,CzPoint p2)
        {
            return (p1.X == p2.X) && (p1.Y == p2.Y);
        }
        public static bool operator !=(CzPoint p1, CzPoint p2)
        {
            return (p1.X != p2.X)|| (p1.Y != p2.Y);
        }
        public class CzLine
        {
            private double a;
            private double b;
            public double A
            {
                get { return this.a; }
            }
            public double B
            {
                get { return this.b; }
            }
            public CzLine(double a, double b)
            {
                this.a = a;
                this.b = b;
            }

            public CzLine(CzPoint p1, CzPoint p2)
            {
                if (p1 == p2)
                    throw new ArgumentException("两点不能相同");
                this.a = (p2.Y - p1.Y) / (p2.X - p1.X);
                this.b = p1.Y - p1.X * this.a;
            }
            public void Move(double b)
            {
                this.b += b;
            }
            public bool Contains(CzPoint p)
            {
                return (p.Y == a * p.X + b);
            }
            public static bool operator==(CzLine cz1,CzLine cz2)
            {
                return (cz1.a == cz2.a) && (cz1.b == cz2.b);
            }
            public static bool operator !=(CzLine cz1, CzLine cz2)
            {
                return (cz1.a == cz2.a) ||(cz1.b == cz2.b);
            }
        }
    }
}
